<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PersonalAlbumModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% foreach (var item in Model.Posts) 
       { %>
       <div class="post_wrapper" id="post_<%=item.ID %>">
       <h1>
            <%= Html.ActionLink<MiniBlogController>(a=>a.Details(item.ID), item.Title ?? "Details")%>
           
        </h1>
        <div class="post_info">
             <span class="post_date1">
                <%=Model.Localize("Blog.postedOn")%>
            </span>
            <span class="post_date2">
                <%= Html.Encode(item.DateCreated.ToString("MMM d yyyy"))%>
            </span>
              <span class="post_author">
                <%if (!string.IsNullOrEmpty(item.UserName))
                  { %>
                |<%=Model.Localize("Blog.by")%>
                <%=item.UserName%>
                <%} %>
           </span>
           <%if (Model.Configuration.ShowReplies && (item.Replies.Count() > 0 || System.Diagnostics.Debugger.IsAttached))
             { %>
                | <span class="post_comments">
                    <%=item.Replies.Count()%>&nbsp;<%=Model.Localize("Blog.Replies")%>
                </span>
           <%} %>
                
        </div>
        <p>
             <%if (Model.User.AllowAddEntries())
               { %>
                 <span>
                     <%= Html.ActionLink(Model.Localize("Blog.edit"), "Edit", new { id = item.ID })%> 
              </span>
                <span>
                    <%using (Html.BeginForm<MiniBlogController>(a => a.Delete(item.ID), FormMethod.Post, new { id = "deletePostForm" }))
                      { %>
                      <%=Html.AntiForgeryToken()%>
                    <a href="javascript:void(0)" onclick="deletePost('<%=item.ID %>');return false;"><%=Model.Localize("Blog.delete")%></a>
                   
                    <%} %>
              </span>
              <% } %>
         
       </p>
       <div class="post_body">
            <%=item.Content%>
       </div>
      </div>
    
    <% } %>
    <%if (Model.User.AllowAddEntries())
      { %>
    <p>
        <%= Html.ActionLink(Model.Localize("Blog.create"), "Create")%>
    </p>
    <%} %>
<script type="text/javascript">
    function deletePost(id) {
        if (!confirm('"<%=Model.Localize("Blog.ConfirmDelete")%>"')) {
            return;
        }
        var form=document.getElementById('deletePostForm');
        $.ajax({
            url: form.action,
            type: form.method,
            data: $(form).serialize(),
            dataType: 'json',
            error: function(e) {
            alert('<%=Model.Localize("Blog.Error") %>');
            }, success: function(j) {
                if (j.success) {
                    $('#post_' + id).remove();
                } else {
                alert('<%=Model.Localize("Blog.Error") %>');
                }
            }
        });
    }
</script>
</asp:Content>

